home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / innd / lc.c < prev    next >
C/C++ Source or Header  |  1993-01-29  |  3KB  |  107 lines

  1. /*  $Revision: 1.12 $
  2. **
  3. **  Routines for the local connect channel.  Create a Unix-domain stream
  4. **  socket that processes on the local server connect to.  Once the
  5. **  connection is set up, we speak NNTP.  The connect channel is used only
  6. **  by rnews to feed in articles from the UUCP sites.
  7. */
  8. #include "innd.h"
  9. #if    defined(DO_HAVE_UNIX_DOMAIN)
  10. #include <sys/un.h>
  11.  
  12. STATIC char    LCpath[] = _PATH_NNTPCONNECT;
  13. STATIC CHANNEL    *LCchan;
  14.  
  15.  
  16. /*
  17. **  Read function.  Accept the connection and create an NNTP channel.
  18. */
  19. STATIC FUNCTYPE
  20. LCreader(cp)
  21.     CHANNEL    *cp;
  22. {
  23.     int        fd;
  24.     CHANNEL    *new;
  25.  
  26.     if (cp != LCchan) {
  27.     syslog(L_ERROR, "%s internal LCreader wrong channel 0x%x not 0x%x",
  28.         LogName, cp, LCchan);
  29.     return;
  30.     }
  31.  
  32.     if ((fd = accept(cp->fd, (struct sockaddr *)NULL, (int *)NULL)) < 0) {
  33.     syslog(L_ERROR, "%s cant accept CCreader %m", LogName);
  34.     return;
  35.     }
  36.     new = NCcreate(fd, FALSE);
  37.     new->Address.s_addr = MyAddress.s_addr;
  38.     syslog(L_NOTICE, "%s connected %d", "localhost", new->fd);
  39. }
  40.  
  41.  
  42. /*
  43. **  Write-done function.  Shouldn't happen.
  44. */
  45. STATIC FUNCTYPE
  46. LCwritedone()
  47. {
  48.     syslog(L_ERROR, "%s internal LCwritedone", LogName);
  49. }
  50. #endif    /* defined(DO_HAVE_UNIX_DOMAIN) */
  51.  
  52.  
  53. /*
  54. **  Create the channel.
  55. */
  56. void
  57. LCsetup()
  58. {
  59. #if    defined(DO_HAVE_UNIX_DOMAIN)
  60.     int            i;
  61.     struct sockaddr_un    server;
  62.  
  63.     /* Remove old detritus. */
  64.     if (unlink(LCpath) < 0 && errno != ENOENT) {
  65.     syslog(L_FATAL, "%s cant unlink %s %m", LogName, LCpath);
  66.     exit(1);
  67.     }
  68.  
  69.     /* Create a socket and name it. */
  70.     if ((i = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
  71.     syslog(L_FATAL, "%s cant socket %s %m", LogName, LCpath);
  72.     exit(1);
  73.     }
  74.     (void)memset((POINTER)&server, 0, sizeof server);
  75.     server.sun_family = AF_UNIX;
  76.     (void)strcpy(server.sun_path, LCpath);
  77.     if (bind(i, (struct sockaddr *)&server, AF_UNIX_SOCKSIZE(server)) < 0) {
  78.     syslog(L_FATAL, "%s cant bind %s %m", LogName, LCpath);
  79.     exit(1);
  80.     }
  81.  
  82.     /* Set it up to wait for connections. */
  83.     if (listen(i, MAXLISTEN) < 0) {
  84.     syslog(L_FATAL, "%s cant listen %s %m", LogName, LCpath);
  85.     exit(1);
  86.     }
  87.     LCchan = CHANcreate(i, CTlocalconn, CSwaiting, LCreader, LCwritedone);
  88.     syslog(L_NOTICE, "%s lcsetup %s", LogName, CHANname(LCchan));
  89.     RCHANadd(LCchan);
  90. #endif    /* defined(DO_HAVE_UNIX_DOMAIN) */
  91. }
  92.  
  93.  
  94. /*
  95. **  Cleanly shut down the channel.
  96. */
  97. void
  98. LCclose()
  99. {
  100. #if    defined(DO_HAVE_UNIX_DOMAIN)
  101.     CHANclose(LCchan, CHANname(LCchan));
  102.     LCchan = NULL;
  103.     if (unlink(LCpath) < 0)
  104.     syslog(L_ERROR, "%s cant unlink %s %m", LogName, LCpath);
  105. #endif    /* defined(DO_HAVE_UNIX_DOMAIN) */
  106. }
  107.